﻿namespace Web.Control.WWW.Files
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
    using BLF.WWW_WWW.Files;
    using System.Collections.Generic;

    /// <summary>
    /// MyDocs 的摘要说明
    /// </summary>
    public class MyDocs : BaseControl
    {
        /// <summary>
        /// 数据类型1：我的文档、2：朋友的文档
        /// </summary>
        protected int DataType = 1;
        /// <summary>
        /// 数据数量
        /// </summary>
        protected int RecordCount = 0;
        /// <summary>
        /// 流行标签列表
        /// </summary>
        protected List<string> TagList = new List<string>();
        protected int pageIndex = 1;
        protected int PageSize = 15;
        protected Repeater rptMyFiles;
        protected Repeater rptFriendF;
        protected Repeater rptPLL;//流行语言
        protected string memberno="";
        protected int DelCount = -1;
        protected override void OnLoad(EventArgs e)
        {   
            memberno = HttpContext.Current.User.Identity.Name;
            if (memberno == "")
            {
                Page.Response.Redirect(WWWHost + "/User/login.htm?ReturnUrl=" + Page.Request.Url.AbsoluteUri.Split('?')[0]);                
                return;
            }
            if (!string.IsNullOrEmpty(Request["dataType"]))
            {
                if (Request["dataType"].ToString().Trim() == "2")
                {
                    DataType = 2;
                }
            }
            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["p"] == "L")
                {
                    pageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out pageIndex);
                    if (pageIndex == 0)
                    {
                        pageIndex = 1;
                    }
                }
            }
            if (DataType == 2)
            {
                ArrayList arrList = Files.GetUserFriendsFiles(memberno, pageIndex, PageSize);
                if (arrList != null)
                {
                    RecordCount = arrList[1] == null ? 0 : (int)arrList[1];
                    if (rptFriendF != null)
                    {
                        rptFriendF.DataSource = arrList[0];
                        rptFriendF.DataBind();
                    }
                    if (rptPLL != null)
                    {
                        List<BLF.LanguageObj> lanObjList = new List<BLF.LanguageObj>();
                        lanObjList.AddRange(BLF.StaticData.GetPopLanguageList);
                        rptPLL.DataSource = lanObjList;
                        rptPLL.DataBind();
                    }
                    TagList = arrList[2] as List<string>; 
                }
            }
            else 
            {
                ArrayList arrList = null;
                if (!string.IsNullOrEmpty(Request["Flag"]) && Request["delID"].Length > 30)
                {
                    arrList = Files.GetMyFiles(memberno, pageIndex, PageSize, Request["delID"].ToString());
                    if (arrList != null&&arrList.Count==3) DelCount = (int)arrList[2];
                }
                else
                {
                    arrList = Files.GetMyFiles(memberno, pageIndex, PageSize);
                }
                if (arrList != null && arrList.Count>1)
                {
                    RecordCount = arrList[1] == null ? 0 : (int)arrList[1];
                    if (rptMyFiles != null)
                    {
                        rptMyFiles.DataSource = arrList[0];
                        rptMyFiles.DataBind();
                    }                    
                }
            }
            int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)PageSize));
            pageIndex = (pageIndex > pCount) ? pCount : pageIndex;            
        }
    }
}
